package com.ruoyi.lease.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.lease.domain.AtbLeaseHouse;
import com.ruoyi.lease.dto.request.StatusDto;
import com.ruoyi.lease.dto.respond.AtbHouseDto;
import com.ruoyi.lease.service.IAtbLeaseHouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 租房审核Controller
 * 
 * @author ruoyi
 * @date 2024-09-16
 */
@RestController
@RequestMapping("/lease/lease")
public class AtbLeaseHouseController extends BaseController
{
    @Autowired
    private IAtbLeaseHouseService atbHouseService;

    /**
     * 查询租房审核列表
     */
    @PreAuthorize("@ss.hasPermi('lease:lease:list')")
    @GetMapping("/list")
    public TableDataInfo list(AtbLeaseHouse atbLeaseHouse)
    {
        startPage();
        List<AtbHouseDto> list = atbHouseService.selectAtbHouseList(atbLeaseHouse);
        return getDataTable(list);
    }

    /**
     * 导出租房审核列表
     */
    @PreAuthorize("@ss.hasPermi('lease:lease:export')")
    @Log(title = "租房审核", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AtbLeaseHouse atbLeaseHouse)
    {
        List<AtbHouseDto> list = atbHouseService.selectAtbHouseList(atbLeaseHouse);
        ExcelUtil<AtbHouseDto> util = new ExcelUtil<AtbHouseDto>(AtbHouseDto.class);
        util.exportExcel(response, list, "租房审核数据");
    }


    /**
     * 租房审核
     */
    @PreAuthorize("@ss.hasPermi('plot:plot:edit')")
    @Log(title = "租房审核", businessType = BusinessType.UPDATE)
    @PutMapping("updateStatus")
    public AjaxResult updateStatus(@RequestBody StatusDto statusDto)
    {
        return toAjax(atbHouseService.updateStatus(statusDto));
    }

    /**
     * 获取租房审核详细信息
     */
    @PreAuthorize("@ss.hasPermi('lease:lease:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(atbHouseService.selectAtbHouseById(id));
    }

    /**
     * 新增租房审核
     */
    @PreAuthorize("@ss.hasPermi('lease:lease:add')")
    @Log(title = "租房审核", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AtbLeaseHouse atbLeaseHouse)
    {
        return toAjax(atbHouseService.insertAtbHouse(atbLeaseHouse));
    }

    /**
     * 修改租房审核
     */
    @PreAuthorize("@ss.hasPermi('lease:lease:edit')")
    @Log(title = "租房审核", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AtbLeaseHouse atbLeaseHouse)
    {
        return toAjax(atbHouseService.updateAtbHouse(atbLeaseHouse));
    }

    /**
     * 删除租房审核
     */
    @PreAuthorize("@ss.hasPermi('lease:lease:remove')")
    @Log(title = "租房审核", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(atbHouseService.deleteAtbHouseByIds(ids));
    }
}
